package com.drinks.yiniang.adapter.user.milepost;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.drinks.yiniang.R;
import com.drinks.yiniang.adapter.user.order.OrderEvaluate2Adapter;
import com.drinks.yiniang.utils.GlideUtils;
import com.hansen.library.listener.OnListItemClickListener;
import com.hansen.library.utils.CommonUtils;

import java.util.List;

/**
 * @author han
 * @date 2019/12/10
 */
public class MilepostBannerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context mContext;

    private List<String> mList;

    private OnListItemClickListener onListItemClickListener;

    public MilepostBannerAdapter(Context context, List<String> list) {
        this.mContext = context;
        this.mList = list;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int i) {
        View v = LayoutInflater.from(mContext).inflate(R.layout.item_milepost_card_banner, parent, false);

        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, final int position) {

        ViewHolder mHolder = (ViewHolder) viewHolder;

        GlideUtils.loadSquareImage(mContext, mHolder.iv_milepost_card_pic, mList.get(position % CommonUtils.getListSize(mList)));

        mHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onListItemClickListener != null) {
                    onListItemClickListener.onItemClick(v, position);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return CommonUtils.getListSize(mList);
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        ImageView iv_milepost_card_pic;

        public ViewHolder(View itemView) {
            super(itemView);

            iv_milepost_card_pic = itemView.findViewById(R.id.iv_milepost_card_pic);
        }
    }
}

